package com.oa.admin.service.impl;

import com.joneying.common.annotation.CommonService;
import com.oa.admin.vo.DepartmentalBudgetDetailsVO;
import com.oa.admin.vo.DepartmentalBudgetListVO;
import com.oa.core.PageResult;
import com.oa.admin.entity.DepartmentalBudget;
import com.oa.admin.mapper.DepartmentalBudgetMapper;
import com.oa.admin.service.IDepartmentalBudgetService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;

/**
 * <p>
 * 部门经费表 服务实现类
 * </p>
 *
 * @author syb123
 * @since 2019-01-22
 */
@Service
public class DepartmentalBudgetServiceImpl extends ServiceImpl<DepartmentalBudgetMapper, DepartmentalBudget> implements IDepartmentalBudgetService {

    private final DepartmentalBudgetMapper departmentalBudgetMapper;

    @Autowired
    public DepartmentalBudgetServiceImpl(DepartmentalBudgetMapper departmentalBudgetMapper) {
        this.departmentalBudgetMapper = departmentalBudgetMapper;
    }

    @Override
    @CommonService
    public PageResult<DepartmentalBudget> findList(Integer pageNum, Integer pageSize) {
        if(pageNum == null){
            List<DepartmentalBudget> list = departmentalBudgetMapper.findList();
            return new PageResult<>(list);
        }else{
            // 当前页，总条数 构造 page 对象
            Page<DepartmentalBudget> page = new Page<>(pageNum, pageSize);
            //查询
            List<DepartmentalBudget> list = departmentalBudgetMapper.findList(page);
            return new PageResult<>(list);
        }
    }

    /**
    * 根据id查询
    */
    @Override
    @CommonService
    public DepartmentalBudgetDetailsVO findDepartmentalBudgetById(String id){
        return departmentalBudgetMapper.findDepartmentalBudgetDetails(id);
    }

    @Override
    public PageResult<DepartmentalBudgetListVO> findDepartmentalBudgetList(Integer pageNum, Integer pageSize, String department) {
        return new PageResult<>(departmentalBudgetMapper.findDepartmentalBudgetList(new Page(pageNum, pageSize), department));
    }
}
